$(function(){

    // 页面初始化...执行获取接口数据的函数....
    getOrderDetail($.getUrlParam('orderId'));

    // 根据订单的id来查询订单的详情.....向后台发送请求....获取接口当中的数据..
    function getOrderDetail(orderId)
    {
        $.ajax({
            type:'post',
            headers: {"Accept-CMS-Token":token},
            url:orderdetails,
            dataType:'json',
            data:{
                orderId:orderId
            },
            success:successFn,
            error:function(){
                console.log('加载部门列表接口请求失败')
            },
        });
    };

    // 跟后台ajax请求接口....成功的时候就执行下面的这个函数...
    function successFn(data)
    {
        if( data.resultCode == 200 )
        {
            $('.orderStatus').html( changeOrderStatus( data.value.order.orderStatus ) );//订单状态
            $('span.expressSendName').html(  data.value.order.expressCompanyName  );//物流信息
            $('span.expressSendName').html(  data.value.order.expressNum  );//物流单号

            $('span.receiveName').html(  data.value.order.receiveName  );//买家信息:收件人
            $('span.receivePhone').html(  data.value.order.receivePhone  );//联系电话
            $('span.receiveAddress').html(  data.value.order.receiveAddress  );//收货地址
            // 展示商品信息
            clearDetailTable('.look_completedOrder_detail');
            var list = data.value.list;
            for( var i = 0;i<list.length;i++ )
            {
                $('.look_completedOrder_detail').append('<tr></tr>');
                $('.look_completedOrder_detail tr').eq(i+1).append('<td>'+(i+1)+'</td>');
                $('.look_completedOrder_detail tr').eq(i+1).append('<td>'+(list[i].ShopCommodity.name)+'</td>');
                $('.look_completedOrder_detail tr').eq(i+1).append('<td>'+(data.value.order.orderNum)+'</td>');
                $('.look_completedOrder_detail tr').eq(i+1).append('<td>'+(list[i].ShopCommodity.colorName)+'</td>');
                $('.look_completedOrder_detail tr').eq(i+1).append('<td>'+(list[i].ShopCommodity.modelName)+'</td>');
                $('.look_completedOrder_detail tr').eq(i+1).append('<td>'+(list[i].ShopCommodity.sizeName)+'</td>');
                $('.look_completedOrder_detail tr').eq(i+1).append('<td>'+(list[i].ShopCommodityOrder.amount)+'</td>');
                $('.look_completedOrder_detail tr').eq(i+1).append('<td>'+(list[i].ShopCommodityOrder.prices)+'</td>');//单价
                $('.look_completedOrder_detail tr').eq(i+1).append('<td>'+(list[i].ShopCommodityOrder.prices)*(list[i].ShopCommodityOrder.amount)+'</td>');//总价
                $('.look_completedOrder_detail tr').eq(i+1).append('<td>'+changeNormalGoods(list[i].ShopCommodityOrder.status)+'</td>');//订单状态
            };
            //展示订单信息
            $('span.totalMoney').html( data.value.order.totalMoney );//订单总金额
            $('span.expressMoney').html( data.value.order.expressMoney );//运费
            $('span.fundsReceived').html( data.value.order.totalMoney + data.value.order.expressMoney );//实收款
            $('span.orderNum').html( data.value.order.orderNum );//订单编号
            $('span.payOrderNum').html( data.value.order.payOrderNum );//支付交易号
            $('span.createTime').html( getMoth(data.value.order.createTime) );//生成时间
            $('span.payTime').html( getMoth(data.value.order.payTime) );//支付时间
            $('span.expressSendTime').html( getMoth(data.value.order.expressSendTime) );//发货时间
            $('span.receiptTime').html( getMoth(data.value.order.endTime) );//完成时间

            console.log(data);
        }
        else if( data.resultCode == 515 )
        {
            reLogin();
        }
        else
        {
            console.log('接口出错!非200,非515!')
        };
        console.log('查询订单详情接口调通!!!!')
    };


});